﻿using System.IO;
using EssionTask;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private TaskChain tc;
        private void button1_Click(object sender, EventArgs e)
        {
            tc = new TaskChain();
            Task t1 = new Task(
               () =>
               {
                   File.AppendAllText(@"t1.txt", "t1");
               }
                );
            Task t2 = new Task(
             () =>
             {
                 Thread.Sleep(4000);
                 File.AppendAllText(@"t1.txt", "t2");
             }
              );

            Task t3 = new Task(
          () =>
          {
              File.AppendAllText(@"t1.txt", "t3");
          }
           );
            List<Task> l = new List<Task>() { t1, t2, t3 };
            tc.ExecuteComplete += tc_ExecuteComplete;
            tc.Tasks = l;

            tc.Execute();

        }

        void tc_ExecuteComplete(object sender, List<Task> e)
        {
            MessageBox.Show("complete");
        }
    }
}
